import { useState, useCallback } from 'react'
import Services from '@/services';

const { auth } = Services

// 范式的简易数据管理方案（部分场景可以取代 dva），通常用于中台项目的全局共享数据
export default function useAuth() {
    const [user, setUser] = useState({ authorized: false })

    const signin = useCallback(async (v) => {
        let userRes = await auth.login(v);
        if (userRes.authorized) {
            setUser(userRes)
        }
    }, [])

    const signout = useCallback(() => {
        // signout implementation
        // setUser(null)
    }, [])

    return {
        user,
        signin,
        signout,
    }
}